<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="PIXINVENT">
    <title>企业人事管理后台</title>
    <link rel="stylesheet" type="text/css" th:href="@{/app-assets/css/vendors.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/app-assets/css/vertical-menu.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/app-assets/css/bootstrap-extended.css}">
</head>
<body>
<div class="content-wrapper">
    <div class="content-header ">
        <div class="content-header-left mb-2">
            <h3 class="content-header-title mb-0">培训管理 </h3>
        </div>
    </div>
    <div class="card">
        <div class="card-content">
            <div class="card-body">
                <div class="searchbox">
                    <div class="form-group">
                        <form class="form-inline" th:action="@{/train}" th:object="${train}"
                              method="get">
<!--                            <div class="form-group">-->
<!--                                <input type="text" class="form-control" th:field="*{employeeId}" placeholder="请输入员工编号">-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <input type="text" class="form-control" th:field="*{trainName}"-->
<!--                                       placeholder="请输入负责人姓名">-->
<!--                            </div>-->
                            <div class="form-group">
                                <input type="text" class="form-control" th:field="*{employeeName}"
                                       placeholder="请输入员工姓名">
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-primary">查询</button>
                            </div>
                        </form>
                        <button type="submit" class="btn btn-success" onclick="add()">增加</button>
                    </div>
                </div>
                <div class="tablebox1">
                    <div style="height: 74vh;overflow: scroll;">
                        <table class="table">
                            <thead>
                            <tr>
<!--                                <th >id</th>-->
<!--                                <th>员工编号</th>-->
                                <th>员工名字</th>
                                <th>负责人姓名</th>
                                <th>培训开始时间</th>
                                <th>培训结束时间</th>
                                <th>是否参加培训</th>
                                <th>实际培训时长</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="el : ${pageInfo.getList()}">
<!--                                <td th:text="${el.id}"></td>-->
<!--                                <td th:text="${el.employeeId}"></td>-->
                                <td th:text="${el.employeeName}"></td>
                                <td th:text="${el.trainName}"></td>
                                <td th:text="${#dates.format(el.startTime,'yyyy-MM-dd')}"></td>
                                <td th:text="${#dates.format(el.overTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                <td th:text="${el.trainAttendace}"></td>
                                <td th:text="${el.trainTime}"></td>
                                <td>
                                    <a href="#" class="btn btn-primary btn-td" th:data-id="${el.id}"
                                       onclick="edit(this.getAttribute('data-id'))">修改</a>
                                    <a href="#" class="btn btn-danger btn-td" th:del-id="${el.id}"
                                       onclick="del(this.getAttribute('del-id'))">删除</a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="page clearfix">
                        <div class="pull-left"
                             th:text="|共  ${pageInfo.getTotal()} 条记录 第 ${pageInfo.getPageNum()} / ${pageInfo.getPages()} 页|"></div>
                        <div class="pull-right">

                            <nav aria-label="..." class="pull-left">
                                <ul class="pagination" th:each=" el : ${pageInfo.getNavigatepageNums()}"
                                    th:switch="${el}">
<!--                                    <li class="disabled"><a href="#" aria-label="Previous"><span-->
<!--                                            aria-hidden="true"></span></a></li>-->
                                    <li th:case="1" class="active"><a
                                            th:href="@{'/train_infor?pageSize=' + ${el}}" th:text="${el}"></a>
                                    </li>
                                    <li th:case="*"><a th:href="@{'/train_infor?pageSize=' + ${el}}"
                                                       th:text="${el}"></a></li>
<!--                                    <li><a href="#" aria-label="Next"><span aria-hidden="true"></span></a></li>-->
                                </ul>
                            </nav>

                            <div class="pull-left p-r-20  p-l-20"><select class="form-control">
                                <option>10条每页</option>
                            </select></div>

                        </div>

                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modal-title1">修改信息</h4>
            </div>
            <from id="myForm" name="myForm">
                <div class="modal-body">
                    <div class="form1 from2">
                        <ul class="row">
                            <li class="col-xs-10">
                                <span>员工编号：</span>
                                <input type="number" class="form-control" name="name" id="edit_employeeId" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>负责人：</span>
<!--                                <input type="text" class="form-control" id="edit_trainId" value="">-->
                                    <select id="trainList"></select>
                            </li>
                            <li class="col-xs-10">
                                <span>是否培训：</span>
                                <input type="number" class="form-control" id="eti_trainAttendace" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>培训时长：</span>
                                <input type="number" class="form-control" id="edit_trainTime" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>开始时间：</span>
                                <input type="datetime-local" class="form-control" id="edit_startTime" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>结束时间：</span>
                                <input type="datetime-local" class="form-control" id="edit_overTime" value="">
                            </li>
                            <li class="col-xs-10">
                                <input type="number" class="form-control" style="display: none;" id="edit_id" value="">
                            </li>
                        </ul>
                    </div>
                </div>
            </from>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="save()">保存</button>
            </div>
        </div>
    </div>
</div>

<script src="../../../static/app-assets/js/vendors.min.js" type="text/javascript"></script>
<script src="../../../static/app-assets/js/app-menu.js" type="text/javascript"></script>
<script src="../../../static/app-assets/js/app.js" type="text/javascript"></script>
<script src="../../../static/app-assets/js/echarts.min.js" type="text/javascript"></script>
<script src="app-assets/js/vendors.min.js" type="text/javascript"></script>
<script src="app-assets/js/app-menu.js" type="text/javascript"></script>
<script src="app-assets/js/app.js" type="text/javascript"></script>
<script src="app-assets/js/echarts.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        $(".ewm").click(function () {
            $(this).toggleClass("active")
        });
    });

    function add() {
        document.getElementById('modal-title1').innerText = '新增用户信息'
        document.getElementById('edit_employeeId').value = ''
        // document.getElementById('edit_trainId').value = ''
        document.getElementById('edit_startTime').value = ''
        document.getElementById('edit_overTime').value = ''
        document.getElementById('eti_trainAttendace').value = ''
        document.getElementById('edit_trainTime').value = ''
        $.get('/attendance_approval/selectTrainerById', function (e, d) {
            console.log(e)
            e.forEach(el => {
                var mySelect = document.createElement("option");
                mySelect.value = el.trainId
                mySelect.text = el.trainName
                document.getElementById('trainList').appendChild(mySelect);
            })
        })
        $('#myModal').modal('show')
    }

    function save() {
        var selects = document.getElementById("trainList");
        var indexs = selects.selectedIndex;  //选中项的索引
        let params = {
            employeeId: document.getElementById('edit_employeeId').value,
            trainId: selects.options[indexs].value,
            startTime: document.getElementById('edit_startTime').value,
            overTime: document.getElementById('edit_overTime').value,
            trainAttendace: document.getElementById('eti_trainAttendace').value,
            trainTime: document.getElementById('edit_trainTime').value,
            id: document.getElementById('edit_id').innerText,
        }
        console.log(params.id)
        if (params.id === null || params.id === '' || params.id === undefined) {
            $.post('train/insert', params, function (e, d) {
                $('#myModal').modal('hide')
                location.reload();
            });
        } else {
            console.log("更新")
            $.post('train/update', params, function (e, d) {
                $('#myModal').modal('hide')
                location.reload();
            });
        }
    }

    function edit(id) {
        document.getElementById('modal-title1').innerText = '修改用户信息'
        $.get('/train/selectById/' + id, function (e, d) {
            console.log(e);
            document.getElementById('edit_employeeId').value = e.employeeId
            //document.getElementById('edit_trainId').value = e.trainId
            document.getElementById('edit_startTime').value = e.startTime
            document.getElementById('edit_overTime').value = e.overTime
            document.getElementById('eti_trainAttendace').value = e.trainAttendace
            document.getElementById('edit_trainTime').value = e.trainTime
            document.getElementById('edit_id').innerText = e.id
            $('#myModal').modal('show')
        })
    }

    function del(id) {
        var x;
        var r = confirm("请确认是否删除该数据！");
        if (r === true) {
            $.get('/train/delete/' + id, function (e, d) {
                location.reload();
            })
        }
    }


</script>
</body>
</html>
